package com.xxxx.server.controller;


import com.xxxx.server.mapper.RoleMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.rest.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IAdminService;
//import com.xxxx.server.utils.QiniuCloudUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */

@RestController
@RequestMapping("/system")
@Api("操作员管理系统,图片上传")
public class AdminController {
    @Autowired
    private IAdminService adminService;
    @Resource
    private RoleMapper roleMapper;

    //查询操作员的信息
   @ApiOperation("操作员用户信息查询")
   @GetMapping("/admin")
    public List<Admin> selectAdminInfo(String keywords){
        return adminService.selectAdminInfo(keywords);
    }





    @GetMapping("/admin/roles")
    @ApiOperation(value="操作员角色查询")
    public List<Role> selectAdminRoleInfo() {
        return adminService.selectAdminRoleInfo();
    }



    //修改操作员的状态(启用和禁用)
    @PutMapping("/admin")
    @ApiOperation(value = "启用和禁用")
    public RespBean updateEnable(@RequestBody Map<String,Object> admin){
        RespBean respBean = adminService.updateEnabledById(admin);
        return  respBean;
    }


    //删除管理员
    @DeleteMapping("/admin/{id}")
    @ApiOperation("删除管理员")
    public RespBean deleteAdmin(@PathVariable Integer id){
        System.out.println(id);
        return adminService.deleteAdminById(id);

    }



    //修改操作员的信息
    @ApiOperation(value = "修改操作员的角色")
    @PutMapping("/admin/role")
    public RespBean updateRoles(Integer adminId,Integer[] rids){
       return adminService.updateRolesById(adminId,rids);
    }



//    @ApiOperation("图片上传;返回url")
//    @RequestMapping (value="/admin/userface", method= RequestMethod.POST)
//    public ResultInfo uploadImg(@RequestParam(value = "file") MultipartFile image, HttpServletRequest request) {
//        ResultInfo result = new ResultInfo();
//        if (image.isEmpty()) {
//            result.setCode(400);
//            result.setMsg("文件为空，请重新上传");
//            return result;
//        }
//        try {
//            byte[] bytes = image.getBytes();
//            String imageName = UUID.randomUUID().toString();
//
//            QiniuCloudUtil qiniuUtil = new QiniuCloudUtil();
//            try {
//                //使用base64方式上传到七牛云
//                String userFace = qiniuUtil.put64image(bytes, imageName);
//                //url设置进数据库
//                  //当前是登录状态
//                   //获取当前用户信息——admin id; update!
//                Admin admin = GetAdminUtils.getAdmin();
//                adminService.updateMyPic(admin.getId(),userFace);
//                result.setCode(200);
//                result.setMsg("文件上传成功");
//                result.setInfo(userFace);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//            return result;
//        } catch (IOException e) {
//            result.setCode(500);
//            result.setMsg("文件上传发生异常！");
//            return result;
//        }
//    }

}
